<div ng-controller="OrderDetailCtrl as vm">
  <h1 class="page-title">运单详情</h1>
  <div class="btn-toolbar" >
    <button ng-show="vm.pickable" class="btn btn-primary" ng-click="vm.sendIntention(vm.order.id)"><i class="icon-ok"></i> 发起意向</button>
    <button ng-show="vm.userRole!='carrier' && vm.order.status==5" class="btn btn-primary" ng-click="vm.confirm(vm.order.id)">确认交单</button>
    <a ng-show="vm.order.status>2" ng-click="vm.viewDriver(vm.order.driver.id)" class="btn btn-primary">查看承运司机</a>
    <a ng-show="vm.order.status>2" ng-click="vm.viewCar(vm.order.vehicle.id)" class="btn btn-primary">查看承运车辆</a>
    <button ng-show="vm.editable && !vm.editing" class="btn btn-primary" ng-click="vm.enableEdit()">修改运单</button>
    <button ng-show="vm.editing" class="btn btn-primary" ng-click="vm.disableEdit()">取消修改</button>
    <div class="btn-group">
      <button ng-show="vm.userRole=='admin' && vm.order.status>2" class="btn btn-primary" ng-click="vm.revert()">状态回退</button>
      <button ng-show="vm.userRole!='carrier' && vm.order.status==2" class="btn btn-primary" ng-click="vm.revert()">删除运单</button>
    </div>
  </div>
  <div class="well">
    <form class="form-horizontal">
      <fieldset>
        <div id="legend" class="">
          <legend class="">基本信息</legend>
        </div>
        <div class="row">
          <div class="span4">
            <div class="control-group">
              <!-- Text input-->
              <label class="control-label" for="input01">运单号</label>
              <div class="controls">
                <input type="text" ng-model="vm.order.orderId" readonly class="input-large">
                <p class="help-block"></p>
              </div>
            </div>
            <div class="control-group">
              <!-- Search input-->
              <label class="control-label">发货号</label>
              <div class="controls">
                <input type="text" ng-model="vm.order.dispatchId" class="input-large " ng-readonly="!vm.editing">
                <p class="help-block"></p>
              </div>
            </div>
            
            
            <div class="control-group">
              <!-- Select Basic -->
              <label class="control-label">始发城市</label>
              <div class="controls" ng-if="!vm.editing">
                <input type="text" ng-model="vm.order.fromCity" class="input-large " ng-readonly="!vm.editing">
                <p class="help-block"></p>
              </div>
              <div class="controls" ng-if="vm.editing">
                <select class="form-control" ng-model="vm.provinceFrom" ng-options="o.name as o.name for o in provinces" ng-change="selectChangeFrom(vm.provinceFrom)">
                  <option value="">省</option>
                </select>
                <select class="form-control" ng-model="vm.cityFrom" ng-options="o.name as o.name for o in citysFrom">
                  <option value="">市</option>
                </select>
                <!-- <input type="text" ng-model="formData.fromCity" class="input-large search-query"> -->
                <p class="help-block"></p>
              </div>
            </div>
            <div class="control-group">
              <!-- Select Basic -->
              <label class="control-label">始发地址</label>
              <div class="controls">
                <textarea rows="3" ng-model="vm.order.addressFrom" ng-readonly="!vm.editing"></textarea>
                <p class="help-block"></p>
              </div>
            </div>
            <div class="control-group">
              <!-- Select Basic -->
              <label class="control-label">到达城市</label>
              <div class="controls" ng-if="!vm.editing">
                <input type="text" ng-model="vm.order.toCity" class="input-large " readonly>
                <p class="help-block"></p>
              </div>
              <div class="controls" ng-if="vm.editing">
                <select class="form-control" ng-model="vm.provinceTo" ng-options="o.name as o.name for o in provinces" ng-change="selectChangeTo(vm.provinceTo)">
                  <option value="">省</option>
                </select>
                <select class="form-control" ng-model="vm.cityTo" ng-options="o.name as o.name for o in citysTo">
                  <option value="">市</option>
                </select>
                <p class="help-block"></p>
              </div>
            </div>
            <div class="control-group">
              <!-- Select Basic -->
              <label class="control-label">到达地址</label>
              <div class="controls">
                <textarea rows="3" ng-model="vm.order.addressTo" ng-readonly="!vm.editing"></textarea>
                <p class="help-block"></p>
              </div>
            </div>
          </div>
          <div class="span3">
            <div class="control-group">
              <!-- Text input-->
              <label class="control-label" for="input01">运单状态</label>
              <div class="controls">
                <select class="input-large" disabled ng-model="vm.order.status" ng-options="o.id as o.name for o in statuses">
                  <option value="">-- 请选择 --</option>
                </select>
                <p class="help-block"></p>
              </div>
            </div>
            <div class="control-group">
              <!-- Select Basic -->
              <label class="control-label">发布运单企业</label>
              <div class="controls">
                <input type="text" ng-model="vm.order.shipper.enterpriseName" class="input-large " readonly>
                <p class="help-block"></p>
              </div>
            </div>
            <div class="control-group">
              <!-- Select Basic -->
              <label class="control-label">发布日期</label>
              <div class="controls">
                <input type="text" ng-model="vm.order.createTime" class="input-large " readonly>
                <p class="help-block"></p>
              </div>
            </div>
            
            
            <div class="control-group">
              <!-- Search input-->
              <label class="control-label">收货人</label>
              <div class="controls">
                <input type="text" placeholder="" ng-show="vm.order.status >2 || vm.userRole!='carrier'" ng-model="vm.order.receiver.name" ng-readonly="!vm.editing" class="input-large ">
                <p ng-show="vm.userRole=='carrier' && vm.order.status==2">无法查看</p>
                <p class="help-block"></p>
              </div>
            </div>
            <div class="control-group">
              <!-- Search input-->
              <label class="control-label">收货人手机</label>
              <div class="controls">
                <input type="text" placeholder="" ng-show="vm.order.status >2 || vm.userRole!='carrier'" ng-model="vm.order.receiver.mobile" ng-readonly="!vm.editing" class="input-large ">
                <p ng-show="vm.userRole=='carrier' && vm.order.status==2">无法查看</p>
                <p class="help-block"></p>
              </div>
            </div>
            <div class="control-group">
              <!-- Search input-->
              <label class="control-label">收货人纳税识别号</label>
              <div class="controls">
                <input type="text" placeholder="" ng-show="vm.order.status >2 || vm.userRole!='carrier'" ng-model="vm.order.receiverTaxerId" ng-readonly="!vm.editing" class="input-large ">
                <p ng-show="vm.userRole=='carrier' && vm.order.status==2">无法查看</p>
                <p class="help-block"></p>
              </div>
            </div>
            <div class="control-group">
              <!-- Search input-->
              <label class="control-label">收货人开户行</label>
              <div class="controls">
                <input type="text" placeholder="" ng-show="vm.order.status >2 || vm.userRole!='carrier'" ng-model="vm.order.receiverBankName" ng-readonly="!vm.editing" class="input-large ">
                <p ng-show="vm.userRole=='carrier' && vm.order.status==2">无法查看</p>
                <p class="help-block"></p>
              </div>
            </div>
            <div class="control-group">
              <!-- Search input-->
              <label class="control-label">收货人银行帐号</label>
              <div class="controls">
                <input type="text" placeholder="" ng-show="vm.order.status >2 || vm.userRole!='carrier'" ng-model="vm.order.receiverBankId" ng-readonly="!vm.editing" class="input-large ">
                <p ng-show="vm.userRole=='carrier' && vm.order.status==2">无法查看</p>
                <p class="help-block"></p>
              </div>
            </div>
            <div class="control-group">
              <!-- Search input-->
              <label class="control-label">收货人注册地址</label>
              <div class="controls">
                <input type="text" placeholder="" ng-show="vm.order.status >2 || vm.userRole!='carrier'" ng-model="vm.order.receiverRegisteredAddress" ng-readonly="!vm.editing" class="input-large ">
                <p ng-show="vm.userRole=='carrier' && vm.order.status==2">无法查看</p>
                <p class="help-block"></p>
              </div>
            </div>
          </div>
        </div>
      </fieldset>
      <fieldset>
        <div id="legend" class="">
          <legend class="">货物及车辆信息</legend>
        </div>
        <div class="row">
          <div class="span4">
            <div class="control-group">
              <!-- Text input-->
              <label class="control-label" for="input01">货物名称</label>
              <div class="controls">
                <input type="text" ng-model="vm.order.cargoName" class="input-large" ng-readonly="!vm.editing">
                <p class="help-block"></p>
              </div>
            </div>
            <div class="control-group">
              <!-- Text input-->
              <label class="control-label" for="input01">货物数量</label>
              <div class="controls">
                <input type="text" ng-model="vm.order.cargoCount" class="input-large" ng-readonly="!vm.editing">
                <p class="help-block"></p>
              </div>
            </div>
            <div class="control-group">
              <!-- Text input-->
              <label class="control-label" for="input01">计重重量</label>
              <div class="controls">
                <input type="text" ng-model="vm.order.weight" class="input-large" ng-readonly="!vm.editing">吨
                <p class="help-block"></p>
              </div>
            </div>
            <div class="control-group">
              <!-- Text input-->
              <label class="control-label" for="input01">计重体积</label>
              <div class="controls">
                <input type="text" ng-model="vm.order.volumn" class="input-large" ng-readonly="!vm.editing">米
                <p class="help-block"></p>
              </div>
            </div>
            <div class="control-group">
              <!-- Search input-->
              <label class="control-label">备用1</label>
              <div class="controls">
                <input type="text" ng-readonly="!vm.editing" ng-model="vm.order.reserved1" class="input-large ">
                <p class="help-block"></p>
              </div>
            </div>
          </div>
          <div class="span3">
            <div class="control-group">
              <!-- Text input-->
              <label class="control-label" for="input01">需求车型</label>
              <div class="controls">
                <input type="text" ng-model="vm.order.requiredVehicleModel" class="input-large" ng-readonly="!vm.editing">
                <p class="help-block"></p>
              </div>
            </div>
            <div class="control-group">
              <!-- Search input-->
              <label class="control-label">其他要求</label>
              <div class="controls">
                <input type="text" ng-model="vm.order.otherRequirement" class="input-large " ng-readonly="!vm.editing">
                <p class="help-block"></p>
              </div>
            </div>
            <div class="control-group">
              <!-- Search input-->
              <label class="control-label">支付方式</label>
              <div class="controls">
                <select class="input-large" ng-model="vm.order.payment" ng-disabled="!vm.editing" ng-options="o for o in payment">
                  <option value="">-- 请选择 --</option>
                </select>
                <p class="help-block"></p>
              </div>
            </div>
            <div class="control-group">
              <!-- Search input-->
              <label class="control-label">支付费用</label>
              <div class="controls">
                <input type="text" ng-model="vm.order.price" class="input-large " ng-readonly="!vm.editing">
                <p class="help-block"></p>
              </div>
            </div>
            <div class="control-group">
              <!-- Search input-->
              <label class="control-label">备用2</label>
              <div class="controls">
                <input type="text" ng-readonly="!vm.editing" ng-model="vm.order.reserved2" class="input-large ">
                <p class="help-block"></p>
              </div>
            </div>
            <div class="control-group">
              <!-- Search input-->
              <label class="control-label">备用3</label>
              <div class="controls">
                <input type="text" ng-readonly="!vm.editing" ng-model="vm.order.reserved3" class="input-large ">
                <p class="help-block"></p>
              </div>
            </div>
          </div>
        </div>
        <div class="control-group">
          <label class="control-label"></label>
          <!-- Button -->
          <div class="controls">
            <button class="btn btn-primary" ng-disabled="uploadid" ng-show="vm.editing" ng-click="vm.processForm()">保存</button>
          </div>
        </div>
      </fieldset>
      
      <fieldset ng-show="vm.order.status==2 && vm.userRole!='carrier'">
        <div id="legend" class="">
          <legend class="">意向者</legend>
        </div>
        <p ng-show="vm.order.intentions.length < 1">还没有意向者</p>
        <div class="table-responsive">
          <table class="table table-striped table-bordered" ng-show="vm.order.intentions.length > 0">
            <thead>
              <tr>
                  <th>服务型企业</th>
                <th>个人用户</th>
                <th>电话</th>
                <th>车辆</th>
                <th>司机</th>
                <th>竞价</th>
                  <!--th>驾龄</th-->
                <th>操作</th>
              </tr>
            </thead>
            <tbody>
              <tr ng-repeat="intention in vm.order.intentions">
                  <td>{{intention.serviceShipper.enterpriseName}}</td>
                  <td>{{intention.carrier.contact.name}}</td>
                <td>{{intention.carrier.contact.mobile}}</td>
                <td>{{intention.vehicle.vehicleNumber}}</td>
                  <td>{{intention.driver.name}}</td>
                  <td>{{intention.price}}</td>
                <!--td>{{intention.driver.firstLicenseDate | toAge}}</td-->
                <td>
                  <a ng-click="vm.viewDriver(intention.driver.id)" class="btn btn-primary">查看司机</a>
                  <a ng-click="vm.viewCar(intention.vehicle.id)" class="btn btn-primary">查看车辆</a>
                  <a ng-click="vm.pickIntention(vm.order.id, intention.id)" class="btn btn-danger">选择接单</a></td>
                </tr>
                
              </tbody>
            </table>
          </div>
        </fieldset>
        <fieldset ng-show="vm.order.status>2">
          <div class="control-group" ng-if="vm.editing">
            <label class="control-label">*上传合同</label>
            <!-- File Upload -->
            <div class="controls">
              <input type="text" id="contract" placeholder="" class="input-large" style="display: none"/>
              <image id="contractImg" style="display: none;" width="30" height="40"></image>
              <a style="cursor: hand" onclick="openUpload('contract')">上传文件</a>
            </div>
          </div>
          <div class="control-group" ng-show="vm.order.contractAttachment">
            <!-- Text input-->
            <label class="control-label" >合同</label>
            <div class="controls">
              <a target="_blank" ng-href="/api/{{vm.order.contractAttachment}}">查看附件</a>
              <p class="help-block"></p>
            </div>
          </div>
        </fieldset>
        <fieldset ng-show="vm.order.status==6 && vm.userRole!='carrier'">
          <div class="control-group" ng-if="vm.editing">
            <label class="control-label">*交单手续</label>
            <!-- File Upload -->
            <div class="controls">
              <input type="text" id="jiaodan" placeholder="" class="input-large" style="display: none"/>
              <image id="jiaodanImg" style="display: none;" width="30" height="40"></image>
              <a style="cursor: hand" onclick="openUpload('jiaodan')">上传文件</a>
            </div>
          </div>
          <div class="control-group" ng-show="vm.order.completionAttachment">
            <!-- Text input-->
            <label class="control-label" >交单手续</label>
            <div class="controls">
              <a target="_blank" ng-href="/api/{{vm.order.completionAttachment}}">查看附件</a>
              <p class="help-block"></p>
            </div>
          </div>
        </fieldset>
      </form>
    </div>
  </div>
  <script>
  function openUpload(inputid){
  var url = "../views/upload.html?id="+ inputid;
  var iWidth=400; //弹出窗口的宽度;
  var iHeight=300; //弹出窗口的高度;
  var iTop = (window.screen.availHeight-30-iHeight)/2; //获得窗口的垂直位置;
  var iLeft = (window.screen.availWidth-10-iWidth)/2; //获得窗口的水平位置;
  window.open(url,'uploadwindow','height='+iHeight+',width='+iWidth+',top='+iTop+',left='+ iLeft +',toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');
  }
  </script>